<?php
function curl_requests($url, $data = array(), $headers = array())
{
// 1. 初始化
    $ch = curl_init();
// 2. 设置选项，包括URL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    if ($data) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
//        print_r($url)."<br>";
    }

    $output = curl_exec($ch);

    if ($output === FALSE) {
        // print_r( curl_getinfo($ch) );
        echo curl_error($ch);
    } else {
        list ($resHeaders, $body) = explode("\r\n\r\n", $output, 2);
        $ret[] = $resHeaders;
        $ret[] = $body;
        return $ret;
    }
    // 4. 释放curl句柄
    curl_close($ch);
    return FALSE;
}
header('Content-type: application/json');
if ($_GET['token']) {
    $token = $_GET['token'];
    $url = 'https://www.heicard.com/fetch/usapi/getIccid?key=3';
    $headers[] = 'token: ' .$token;
    $ret = curl_requests($url, array(), $headers);
    echo $ret[1];
}
